<script>
init({
  title: 'Detail View Align',
  desc: 'Use `detailViewAlign` option to align the detail view icon.',
  links: ['bootstrap-table.min.css'],
  scripts: ['bootstrap-table.min.js']
})
</script>

<template>
  <div class="toolbar">
    <label class="checkbox-inline">
      <input
        type="radio"
        name="detailViewAlign"
        value="left"
      >
      <code>left</code>
    </label>
    <label class="checkbox-inline">
      <input
        type="radio"
        checked
        name="detailViewAlign"
        value="right"
      >
      <code>right</code>
    </label>
  </div>

  <table
    id="table"
    data-height="460"
    data-detail-view="true"
    data-detail-filter="detailFilter"
    data-show-footer="true"
    data-toolbar=".toolbar"
    data-url="json/data1.json"
  >
    <thead>
      <tr>
        <th
          data-field="id"
          data-valign="middle"
          rowspan="2"
          data-footer-formatter="idFormatter"
        >
          ID
        </th>
        <th colspan="2">
          Detail
        </th>
      </tr>
      <tr>
        <th
          data-field="name"
          data-footer-formatter="footerFormatter"
        >
          Item Name
        </th>
        <th
          data-field="action"
          data-formatter="actionFormatter"
          data-events="actionEvents"
          data-footer-formatter="footerFormatter"
        >
          Action
        </th>
      </tr>
    </thead>
  </table>
</template>

<script>
  const $table = $('#table')

  window.actionEvents = {
    'click .btn' () {
      alert('Click')
    }
  }

  function mounted () {
    $('.toolbar input').change(function () {
      const detailViewAlign = $('.toolbar input:checked').val()

      $table.bootstrapTable('refreshOptions', {
        detailViewAlign
      })
    })

    $table.bootstrapTable({
      detailViewAlign: 'right'
    })
  }

  window.detailFilter = index => index % 2 === 0

  window.idFormatter = () => 'Total'

  window.footerFormatter = data => data.length

  window.actionFormatter = () => '<button class="btn btn-secondary">Click</button>'
</script>
